/*
 * KEY.c
 *
 *  Created on: 2025年7月5日
 *      Author: 黄少杰
 */

#include "key.h"



uint8_t key_val = 0 , key_down = 0, key_old = 0;
uint8_t key = 0;
void key_state()
{

    bsp_io_level_t p_port_value_pin_000;
    bsp_io_level_t p_port_value_pin_001;
    bsp_io_level_t p_port_value_pin_002;

    R_IOPORT_PinRead(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_00, &p_port_value_pin_000);
    R_IOPORT_PinRead(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_01, &p_port_value_pin_001);
    R_IOPORT_PinRead(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_02, &p_port_value_pin_002);

    if(!p_port_value_pin_000)
    {
        R_BSP_SoftwareDelay(100,BSP_DELAY_UNITS_MILLISECONDS);
       if(!p_port_value_pin_000)
       {
           key = 2;
           R_BSP_SoftwareDelay(100,BSP_DELAY_UNITS_MILLISECONDS);
       }

    }
    else if(!p_port_value_pin_001)
    {
        R_BSP_SoftwareDelay(100,BSP_DELAY_UNITS_MILLISECONDS);
       if(!p_port_value_pin_001)
       {
           key = 3;
           R_BSP_SoftwareDelay(100,BSP_DELAY_UNITS_MILLISECONDS);
       }
    }
    else if(!p_port_value_pin_002)
    {
        R_BSP_SoftwareDelay(100,BSP_DELAY_UNITS_MILLISECONDS);
       if(!p_port_value_pin_002)
       {
           key = 4;
           R_BSP_SoftwareDelay(100,BSP_DELAY_UNITS_MILLISECONDS);
       }
    }

//    key = 5;


//    key_val = key;
//    key_down = key_val & (key_val ^ key_old);
//    key_old = key_val;

}
